package com.ruoyi.biz.controller;

import com.ruoyi.collect.domain.Collections;
import com.ruoyi.collect.service.ICollectionsService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 收藏夹主（支持分类）Controller
 * 
 * @author ruoyi
 * @date 2025-08-13
 */
@RestController
@RequestMapping("/collect/collections")
public class CollectionsController extends BaseController
{
    @Autowired
    private ICollectionsService collectionsService;

    /**
     * 查询收藏夹主（支持分类）列表
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(Collections collections)
    {
        startPage();
        List<Collections> list = collectionsService.selectCollectionsList(collections);
        return getDataTable(list);
    }

    /**
     * 导出收藏夹主（支持分类）列表
     */
    @Anonymous
    @Log(title = "收藏夹主（支持分类）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Collections collections)
    {
        List<Collections> list = collectionsService.selectCollectionsList(collections);
        ExcelUtil<Collections> util = new ExcelUtil<Collections>(Collections.class);
        util.exportExcel(response, list, "收藏夹主（支持分类）数据");
    }

    /**
     * 获取收藏夹主（支持分类）详细信息
     */
    @Anonymous
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(collectionsService.selectCollectionsById(id));
    }

    /**
     * 新增收藏夹主（支持分类）
     */
    @Anonymous
    @Log(title = "收藏夹主（支持分类）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Collections collections)
    {
        return toAjax(collectionsService.insertCollections(collections));
    }

    /**
     * 修改收藏夹主（支持分类）
     */
    @Anonymous
    @Log(title = "收藏夹主（支持分类）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Collections collections)
    {
        return toAjax(collectionsService.updateCollections(collections));
    }

    /**
     * 删除收藏夹主（支持分类）
     */
    @Anonymous
    @Log(title = "收藏夹主（支持分类）", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(collectionsService.deleteCollectionsByIds(ids));
    }


    //-----------------------------------
    @Anonymous
    @GetMapping("/select/page")
    public Object findPage(@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                           @RequestParam(value = "pageSize", required = false, defaultValue = "2") Integer pageSize,
                           Collections collections) {
        return collectionsService.findpage(pageNum, pageSize, collections);
    }

    @Anonymous
    @GetMapping("/select/{id}")
    public Collections findById(@PathVariable("id") String id) {
        return collectionsService.findById(id);
    }

    @Anonymous
    @GetMapping("/select")
    public List<Collections> find(){
        return collectionsService.findAllCollections();
    }

    @Anonymous
    @DeleteMapping("/delete/{id}")
    public String delete(@PathVariable int id) {
        return collectionsService.remove(id) > 0 ? "删除成功" : "删除失败";
    }
    @DeleteMapping("/delete")
    public String deleteBatch(Integer[] ids){
        return collectionsService.removeBatch(ids)> 0 ? "批量删除成功" : "批量删除失败";
    }

}




